package com.future.esdemo.domain;

import com.baomidou.mybatisplus.annotation.TableName;
import com.future.esdemo.domain.TaskPending;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.beans.BeanUtils;

import java.io.Serializable;
import java.util.Date;

/**
 * @author future
 * @title: Task
 * @description: 任务表 合并了taskPending\taskExecuting\taskFinished 三张表的数据 2022-03-29 新建 临时过渡使用
 * @date 2022-03-29 18:02
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
@TableName("task_all")
public class TaskAll implements Serializable {

    public TaskAll(TaskPending taskPending) {
        super();
        BeanUtils.copyProperties(taskPending, this);
    }

    public TaskAll(String id, int status) {
        super();
        this.id = id;
        this.status = status;
    }

    public TaskAll(String id, Date executeTime, String executorId, int status) {
        super();
        this.id = id;
        this.executeTime = executeTime;
        this.executorId = executorId;
        this.status = status;
    }

    //任务id
    private String id;
    //新建时间
    private Date createTime;
    //进入执行时间
    private Date executeTime;
    //结束执行时间
    private Date finishTime;
    //结果推送状态 1无需推送 2未推送 3推送成功 4推送失败
    private String resultPushState;
    //结果推送描述 当resultPushState为4 时存在
    private String resultPushMsg;
    //推送次数
    private Integer retryCounts;
    //推送接收反馈时间
    private Date feedTime;
    //推送耗时
    private Long tshs;
    //任务标签
    private String label;
    //所属业务id
    private String businessId;
    //执行者Id
    private String executorId;
    //任务类型id
    private String tasktypeId;
    //执行次数
    private Integer executeCount;
    //最大执行次数
    private Integer maxExecuteCount;
    //业务系统查询属性1
    private String queryField1;
    //业务系统查询属性2
    private String queryField2;
    //优先级
    private Integer priority;
    //来源 1 开放平台 2 同consumerId 3
    private String source;
    private String xzqhdm;
    //二级标签 单个
    private String secondaryLabel;
    //扩展
    private String extension;
    //拾取方式 TODO  未实现 0 固定（默认值）   1 随意 可以被设置动态二级标签额执行者拾取（非二级标签、公开执行者等）
    private String secondaryLabelMode = "1";
    //状态 1 待处理  2 处理中  3 已处理 4技术失败
    private int status = 1;

    /**
     * 创建待处理状态全局任务
     *
     * @param taskId 任务id
     * @return taskAll
     */
    public static TaskAll makePendingStateTaskAll(String taskId) {
        TaskAll task = new TaskAll();
        task.setId(taskId);
        task.setStatus(1);
        return task;
    }

    /**
     * 创建处理中状态全局任务
     *
     * @param taskId      任务id
     * @param executeTime 执行时间
     * @return taskAll
     */
    public static TaskAll makeExecutingStateTaskAll(String taskId, Date executeTime) {
        TaskAll task = new TaskAll();
        task.setId(taskId);
        task.setExecuteTime(executeTime);
        task.setStatus(2);
        return task;
    }

    /**
     * 创建已完成状态全局任务
     *
     * @param taskId     任务id
     * @param finishTime 完成时间
     * @return taskAll
     */
    public static TaskAll makeFinishStateTaskAll(String taskId, Date finishTime) {
        TaskAll task = new TaskAll();
        task.setId(taskId);
        task.setFinishTime(finishTime);
        task.setStatus(3);

        return task;
    }

    /**
     * 创建已挂起状态全局任务
     *
     * @param taskId     任务id
     * @param finishTime 完成时间
     * @return taskAll
     */
    public static TaskAll makeSuspendedStateTaskAll(String taskId, Date finishTime) {
        TaskAll task = new TaskAll();
        task.setId(taskId);
        task.setFinishTime(finishTime);
        task.setStatus(4);
        return task;
    }

    public static String ES_SOURCE = "{\n" +
            "\t\"mappings\": {\n" +
            "\t\t\"properties\": {\n" +
            "\t\t\t\"id\": {\n" +
            "\t\t\t\t\"type\": \"keyword\"\n" +
            "\t\t\t},\n" +
            "\t\t\t\"createTime\": {\n" +
            "\t\t\t\t\"type\": \"date\"\n" +
            "\t\t\t},\n" +
            "\t\t\t\"executeTime\": {\n" +
            "\t\t\t\t\"type\": \"date\"\n" +
            "\t\t\t},\n" +
            "\t\t\t\"finishTime\": {\n" +
            "\t\t\t\t\"type\": \"date\"\n" +
            "\t\t\t},\n" +
            "\t\t\t\"resultPushState\": {\n" +
            "\t\t\t\t\"type\": \"keyword\"\n" +
            "\t\t\t},\n" +
            "\t\t\t\"resultPushMsg\": {\n" +
            "\t\t\t\t\"type\": \"text\"\n" +
            "\t\t\t},\n" +
            "\t\t\t\"retryCounts\": {\n" +
            "\t\t\t\t\"type\": \"integer\"\n" +
            "\t\t\t},\n" +
            "\t\t\t\"feedTime\": {\n" +
            "\t\t\t\t\"type\": \"date\"\n" +
            "\t\t\t},\n" +
            "\t\t\t\"tshs\": {\n" +
            "\t\t\t\t\"type\": \"long\",\n" +
            "\t\t\t\t\"index\": false\n" +
            "\t\t\t},\n" +
            "\t\t\t\"label\": {\n" +
            "\t\t\t\t\"type\": \"keyword\"\n" +
            "\t\t\t},\n" +
            "\t\t\t\"businessId\": {\n" +
            "\t\t\t\t\"type\": \"keyword\"\n" +
            "\n" +
            "\t\t\t},\n" +
            "\t\t\t\"executorId\": {\n" +
            "\t\t\t\t\"type\": \"keyword\"\n" +
            "\t\t\t},\n" +
            "\t\t\t\"tasktypeId\": {\n" +
            "\t\t\t\t\"type\": \"keyword\"\n" +
            "\t\t\t},\n" +
            "\t\t\t\"executeCount\": {\n" +
            "\t\t\t\t\"type\": \"integer\"\n" +
            "\t\t\t},\n" +
            "\t\t\t\"maxExecuteCount\": {\n" +
            "\t\t\t\t\"type\": \"integer\"\n" +
            "\t\t\t},\n" +
            "\t\t\t\"queryField1\": {\n" +
            "\t\t\t\t\"type\": \"text\"\n" +
            "\t\t\t},\n" +
            "\t\t\t\"queryField2\": {\n" +
            "\t\t\t\t\"type\": \"text\"\n" +
            "\t\t\t},\n" +
            "\t\t\t\"priority\": {\n" +
            "\t\t\t\t\"type\": \"integer\"\n" +
            "\t\t\t},\n" +
            "\t\t\t\"source\": {\n" +
            "\t\t\t\t\"type\": \"keyword\"\n" +
            "\t\t\t},\n" +
            "\t\t\t\"xzqhdm\": {\n" +
            "\t\t\t\t\"type\": \"keyword\"\n" +
            "\t\t\t},\n" +
            "\t\t\t\"secondaryLabel\": {\n" +
            "\t\t\t\t\"type\": \"text\"\n" +
            "\t\t\t},\n" +
            "\t\t\t\"extension\": {\n" +
            "\t\t\t\t\"type\": \"text\"\n" +
            "\t\t\t},\n" +
            "\t\t\t\"status\": {\n" +
            "\t\t\t\t\"type\": \"integer\"\n" +
            "\t\t\t}\n" +
            "\t\t}\n" +
            "\t}\n" +
            "}";
}
